/*
Copyright 2010  Murali Devi (profdevi@gmail.com)

This file is part of ComineGL Project.

ComineGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ComineGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ComineGL.  If not, see <http://www.gnu.org/licenses/>.

This code uses the irrlicht and irrklang libraries.  Please read
the libraries copyrights at 

	irrlicht library:  http://irrlicht.sourceforge.net
	irrklang library:  http://www.ambiera.com/irrklang

*/



//v1.4 copyright Comine.com 20101211S22
#ifndef MCGLEventInput_h
#define MCGLEventInput_h

/////////////////////////////////////////////////////
#include "MStdLib.h"
#include "MIrrlicht.h"

/*
	Slows down input from both mouse and keyboard to only a single 
	time resolution, so repeated keys dont get accepted faster then
	the time resolution.
*/

//******************************************************
//**  MCGLEventInput class
//******************************************************
class MCGLEventInput:public IEventReceiver
	{
	////////////////////////////////////////////////
	IrrlichtDevice *mIrrlichtDevice;
	unsigned int mKeyPressTime[KEY_KEY_CODES_COUNT];	
	int mKeyIsPressedCount[KEY_KEY_CODES_COUNT];	// Is Key Presses Count Time

	unsigned int mClockTime;						// Hold the clock time
	unsigned int mMouseTime;						// Holds time when mouse was moved in ms
	int mMousePosX;									// Mouse Position (x,y)
	int mMousePosY;

	int mMouseDeltaX;								// Delta Position of mouse from last position
	int mMouseDeltaY;

	unsigned int mMouseRightClickTime;				// Hold the time of last Right Click Time
	unsigned int mMouseLeftClickTime;				// Hold the time of last Left Click Time

	// Raw Keyboard Handler
	bool (*mRawKeyboardHandler)(int keycode,void *extra);
	void *mRawKeyboardHandlerExtra;

	////////////////////////////////////////////////
	void ClearObject(void);
	
	////////////////////////////////////////////////
	public:
	MCGLEventInput(void);
	~MCGLEventInput(void);
	bool Create(IrrlichtDevice *device);
	bool Destroy(void);
	
	// Virtual Interface
	virtual bool OnEvent(const SEvent& event);

	// Handle keyboard input
	bool IsKeyPressed(int keycode);					// Check if key is pressed
	bool GetMousePosition(int &x,int &y);			// Get Mouse Position
	bool GetMouseDelta(int &dx,int &dy);			// Get Mouse Delta Position
	bool UpdateTime(void);							// Must be called continuosly to get correct timings
	bool IsMouseRightPressed(void);					// = true if right mouse button was pressed
	bool IsMouseLeftPressed(void);					// = true if left mouse button was pressed

	// Raw Call Back Function
	bool SetKeyboardHandler(bool KeyboardHandler(int keycode,void *extra),void *extra=NULL);
	};

#endif // MCGLEventInput_h

